import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isCollapse: false,
    rightTopNav: [],
    editableTabs: [
      {
        title: '首页',
        src: '/examIndex',
        name: "1"
      }
    ],
    editableTabsValue: "1",
    tabIndex: 1,
    ViewSrc: '',
    ESpageIndex:1,//学科列表第几页
    ESpageSize:10,//学科列表第几条
    EStableData:[],//学科列表数据
    EStableData1:[],//学科列表数据1
    aaaa:{},
    statedList:{}
  },
  getters: {

  },
  mutations: {
    //点击编辑
    state(state,data){
      state.aaaa=data
      console.log(state.aaaa)
    },

    stated(state,data){
      state.statedList=data
      console.log(state.statedList)
    },


    // 左侧点击修改显示
    leftClickChange(state, name) {
      state.tabIndex = name * 1;
      state.editableTabsValue = name * 1 + '';
    },
    changeisCollapse(state) {
      // console.log(state.isCollapse);
      state.isCollapse = !state.isCollapse
    },
    changeTop(state, arr) {
      state.rightTopNav = [];
      // console.log(arr);
      arr.forEach(item => {
        if (item.name != '主页面') {
          // console.log(item);
          let { name, path } = item;
          let obj = { text: name, path }
          state.rightTopNav.push(obj)
        }
      })
    },
    // 改变面包屑
    changeBread(state, obj) {
      let obj1 = {
        title: obj.title,
        src: obj.src,
        name: obj.name,
      }
      let some = state.editableTabs.some(res => res.title == obj1.title)
      if (some) {
        return;
      }
      let newTabName = ++state.tabIndex + '';
      console.log(state.tabIndex);
      state.editableTabs.push(obj1);
      state.editableTabsValue = newTabName;
    },
    removeBread(state, obj) {
      let tabs = state.editableTabs;
      let activeName = state.editableTabsValue;
      if (activeName === obj) {
        tabs.forEach((tab, index) => {
          if (tab.name === obj) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              state.ViewSrc = nextTab.src;
              activeName = nextTab.name;
            }
          }
        });
      }

      state.editableTabsValue = activeName;
      state.editableTabs = tabs.filter(tab => tab.name !== obj);
    },
    // 请求学科分页
    EShttp(state) {
      axios({
        method: "post",
        url: '/api/admin/education/subject/page',
        data: {
          "level": null,  //年级
          "pageIndex": state.ESpageIndex,
          "pageSize": state.ESpageSize
        }
      }).then(res => {
        console.log(state.ESpageIndex,state.ESpageSize);
        let data = res.data.response.list
        state.EStableData = data
        state.EStableData1 = data
      })
    },
  },
  actions: {
    
  },
  modules: {
  }
})
